var common = require("../../../utils/common.js");
var app = getApp();
Page({
    data: {
        status: true,
        hidden: false,
        indicatorDots: true,
        autoplay: true,
        interval: 125000,
        duration: 1000,
        todayList: [],
        articleList: [],
        pageNo: 1
    },
    onLoad: function(){
        var that = this;
        app.getSystemInfo(function(systemInfo){
            //更新数据
            that.setData({
                systemInfo:systemInfo
            })
        })
        common.reqService("/Article/ArticleList", {}, that.data.systemInfo, "GET", function(res){
            var todayList = res.data.today_article;
            var articleList = res.data.article_list;
            that.setData({"hidden":true,"todayList": todayList, "articleList": articleList});
        })
    },
    articleDetail: function(event){
        var articleId = event.currentTarget.dataset.articleId;
        wx.navigateTo({
            url: '../detail/index?id='+articleId
        })
    },
    articleRedirect: function(event){
        common.toast(this, '暂不支持此功能');
    },
    getMoreArticle: function(){
        var that = this;
        var pageNo = parseInt(this.data.pageNo);
        var articleList = this.data.articleList;
        pageNo++;

        that.setData({"hidden": false});
        common.reqService("/Article/ArticleList", {"p": pageNo}, that.data.systemInfo, false, function(res){
            that.setData({"hidden": true});
            if(res.data.length > 0){
                for(r in res.data){
                    articleList.push(res.data[r]);
                }
                that.setData({"pageNo": pageNo, "articleList": articleList});
            }else{
                common.toast(that, "没有更多内容");
            }
        })
    },
    hiddenToast: function(){
      this.setData({status: true, msg:''});
    }
})